<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>YUI History Test</title>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <script src="./prototype.js"></script>
  <script src="./builder.js"></script>
  <!-- Dependencies -->
  <script src="http://yui.yahooapis.com/2.4.1/build/yahoo/yahoo-min.js"></script>
  <script src="http://yui.yahooapis.com/2.4.1/build/event/event-min.js"></script>
  <!-- Browser History Manager source file -->
  <script src="http://yui.yahooapis.com/2.4.1/build/history/history-min.js"></script>
  <style type="text/css">
  <!--
  #yui-history-iframe { 
    position:absolute; 
    top:0; left:0; 
    width:1px; height:1px; 
    visibility:hidden; 
  } 
  -->
  </style>
</head>
<body>
<iframe id="yui-history-iframe" src="./blank2.html"></iframe> 
<input id="yui-history-field" type="hidden">
<script>
var cont_table=[];
var query_table=[];
var kurl = 0;

function show(){
  var e = $('msg');
  while (e.firstChild) e.removeChild(e.firstChild);
  $A(arguments).each(function(node) {e.appendChild(node)});
}

function cont(q,f) {
  kurl++;
  query_table["myModuleNewState" + kurl] = q;
  cont_table["myModuleNewState" + kurl] = f;
  var t = '' + kurl;
  return function(){
    YAHOO.util.History.navigate('myModule','myModuleNewState' + t)
  }
}

function do_cont(state) {
  if (state == "myModuleDefaultState") {
    main();
  } else {
    if (typeof query_table[state] == "function") query_table[state] = query_table[state]();
    cont_table[state](query_table[state]);
  }
}

function main() {
  function q0() {return {x: $F("said")}};
  show(INPUT({type:"text",id:"said"}),BUTTON({id:"button"},"submit")); 
  $("button").onclick = cont(q0,function(query) {    
    var said = query["x"];
    show(A({id: "a", href:"javascript:void(0)"},"click here")); 
    $("a").onclick = cont(null,function(query) {
      show(SPAN("you said " + said))})});
}

(function () {
  var myModuleBookmarkedState = YAHOO.util.History.getBookmarkedState("myModule");
  var myModuleInitialState = myModuleBookmarkedState || "myModuleDefaultState";
  function myModuleStateChangeHandler (state) {
    do_cont(state);
  }
  YAHOO.util.History.register("myModule", myModuleInitialState, myModuleStateChangeHandler);
  YAHOO.util.History.onReady(function () {
    var myModuleCurrentState = YAHOO.util.History.getCurrentState("myModule");
    do_cont(myModuleCurrentState);
  });
  try {
    YAHOO.util.History.initialize("yui-history-field", "yui-history-iframe");
  } catch (e) {
    document.getElementById("msg").innerHTML = "Sorry, your browser(maybe Opera?) is not supported";
  };
  Builder.dump();
})();
</script>
<div id="msg"></div>
</body>
</html>
